import tkinter as tk
from tkinter import filedialog

root = tk.Tk()

def select_file():
    file_path = filedialog.askopenfilename(filetypes=[("Excel files", "*.xlsx;*.xls")])
    if file_path:
        file_path_label.config(text=file_path)

# 创建一个框架用于放置按钮和标签
button_label_frame = tk.Frame(root)
button_label_frame.pack()

# 创建并布局选择文件按钮
file_select_button = tk.Button(
    button_label_frame, text="选择 Excel 文件", command=select_file)
file_select_button.pack(side=tk.LEFT, pady=5, padx=5)

# 创建并布局文件路径标签
file_path_label = tk.Label(button_label_frame, text="未选择文件")
file_path_label.pack(side=tk.LEFT, pady=5, padx=5)

# 创建一个布尔型变量来存储复选框的状态
checkbox_var = tk.BooleanVar()
# 初始化复选框状态为未选中
checkbox_var.set(False)

# 创建并布局复选框
checkbox = tk.Checkbutton(root, text="记住选择", variable=checkbox_var)
checkbox.pack(pady=5, padx=5)

root.mainloop()